package cn.jaye.fabric.controller;

import cn.jaye.fabric.application.command.CreateAccessPointCommand;
import cn.jaye.fabric.application.command.EnableStateCommand;
import cn.jaye.fabric.application.AccessPointApplicationService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

/**
 * @author Jaye
 * @create 2017-12-21 13:34
 */
@Controller
@RequestMapping("/accesspoint")
public class AccessPointController {

    @Autowired
    private AccessPointApplicationService accessPointApplicationService;

    @RequestMapping("/firstpage")
    public String firstPage() {
        return "acc_firstPage";
    }

    @PostMapping("/list")
    @ResponseBody
    public String list() {
        return accessPointApplicationService.listAccessPoint();
    }

    @PostMapping("/create")
    @ResponseBody
    public String create(@ModelAttribute CreateAccessPointCommand createAccessPointCommand) {
        return accessPointApplicationService.createAccessPoint(createAccessPointCommand);
//        return "{\"code\":1000,\"data\":{\"executeResult\":true},\"msg\":\"success\"}";
    }

    @PostMapping("/enable")
    @ResponseBody
    public String enable(EnableStateCommand enableStateCommand) {
        return accessPointApplicationService.enableAccessPoint(enableStateCommand);
    }

    @PostMapping("/disable")
    @ResponseBody
    public String disable(EnableStateCommand enableStateCommand) {
        return accessPointApplicationService.disableAccessPoint(enableStateCommand);
    }
}
